﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMS.DAL;
using SMS.DAL.Providers;

namespace SMS.Business
{
    public class OrderBusiness : BusinessBase<Order,OrderSearchCriteria>
    {
        OrderProvider orderProvider;
        public OrderBusiness()
        {
            orderProvider = new OrderProvider();
        }
        public override bool Insert(Order item)
        {
            throw new NotImplementedException();
        }

        public int InsertOrder(Order item)
        {
            orderProvider.InsertOrder(item);
            return item.ID;
        }

        public StockUser GetUserStockByUserIDandStockID(StockUserSearchCriteria search)
        {
            StockUsersProvider provider = new StockUsersProvider();
            return provider.GetByUserIDandStockID(search);
        }

        public override bool Update(Order updatedItem)
        {
            throw new NotImplementedException();
        }

        public override bool Delete(int id)
        {
            OrderItemsBussiness orderItemBus = new OrderItemsBussiness();
            orderItemBus.DeleteByOrderID(id);
            return true;
        }

        public override Order GetByID(int id)
        {
            return orderProvider.GetByID(id);
        }

        public override List<Order> Search(OrderSearchCriteria SearchCriteria)
        {
            return orderProvider.Search(SearchCriteria);
        }

        public StockItem GetStockItemByBarCode(string barcode,int stockID)
        {
            StockItemsProvider provider = new StockItemsProvider();
            ItemSearchCriteria itemSearch = new ItemSearchCriteria()
            {
                Barcode = barcode,
                StockID = stockID
            };
            return provider.GetByBarcode(itemSearch);
        }

        public StockItem GetStockItemByItemNameAndItemMark(string itemName, string itemMark, int StockID)
        {
            StockItemsProvider stockItemProvider = new StockItemsProvider();
            return stockItemProvider.Search(itemName, itemMark, StockID).FirstOrDefault();
        }

    }
}